package com.dhj.jvmstudy.chapter05;

import java.util.ArrayList;
import java.util.Random;

/**
 * OutOfMemoryEroor错误测试
 */
public class OOMTest {

    /**
     * Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
     * 	at com.dhj.jvmstudy.chapter05.OOMTest$Picture.<init>(OOMTest.java:25)
     * 	at com.dhj.jvmstudy.chapter05.OOMTest.main(OOMTest.java:15)
     */
    public static void main(String[] args) throws InterruptedException {
        ArrayList<Picture> list = new ArrayList<>();
        while (true){
            Thread.sleep(200);
            list.add(new Picture(new Random().nextInt(1024*1024)));
        }

    }


    static class Picture {
        private byte[] pixels;

        public Picture(int length){
            this.pixels = new byte[length];
        }
    }

}

